package rmmk.ksr.experiments;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;

import rmmk.algorithms.features.FeatureManager;
import rmmk.algorithms.features.FrequentNumbersGlobal;
import rmmk.algorithms.features.fatures.NumbersWordsExtractor;
import rmmk.algorithms.features.global.PairsOfWordsGlobal;
import rmmk.algorithms.preprocessing.OperationManager;
import rmmk.algorithms.preprocessing.WordExtractor;
import rmmk.algorithms.preprocessing.abstraction.IWordFilter;
import rmmk.algorithms.preprocessing.filters.ToLowercaseNoInterpunctionFilter;
import rmmk.datasources.parsing.ClassTypes;
import rmmk.datasources.parsing.DocumentReader;
import rmmk.framework.Analize;
import rmmk.framework.datasources.Document;
import rmmk.framework.datasources.DocumentSetSelector;

public class Experiments {

	@Test
	public void experiment1() {
		Long start = System.nanoTime();

		OperationManager om = new OperationManager();

		DocumentReader dr = new DocumentReader();

		List<Document> allDocuments = dr.readDefautDocuments();

		IWordFilter[] iwe = new IWordFilter[] { new ToLowercaseNoInterpunctionFilter() };
		WordExtractor.extractWords(allDocuments, Arrays.asList(iwe));

		DocumentSetSelector dss = new DocumentSetSelector(allDocuments);
		dss.addDesiredCategory(ClassTypes.PLACES);
		dss.setLimit(1);
		dss.addCategoryName("west-germany");
		dss.addCategoryName("usa");
		dss.addCategoryName("france");
		dss.addCategoryName("uk");
		dss.addCategoryName("canada");
		dss.addCategoryName("japan");

		List<Document> trainDocuments = dss.getTrainSet();

		PairsOfWordsGlobal pwg = new PairsOfWordsGlobal();
		pwg.calculate(trainDocuments);
		FrequentNumbersGlobal ng = new FrequentNumbersGlobal();
		ng.calculate(trainDocuments);

		FeatureManager fm = new FeatureManager();
		// fm.addFeature(new PairsOfWordsExtractor(43), new NumberExtractor(5),
		// new NumbersWordsExtractor());
		fm.addFeature(new NumbersWordsExtractor());

		om.setFeatureManager(fm);

		om.teach(trainDocuments);

		om.setK(9);

		List<Document> testDocuments = dss.getTestSet();

		testDocuments = om.predict(testDocuments);

		Analize.analize(testDocuments);
		Long finished = System.nanoTime();

		System.out.println("Czas " + (finished - start) / 1000000000 + " sekund");
	}
}
